package com.zfei.gfb.util.gson;

import com.google.gson.FieldNamingStrategy;
import com.zfei.gfb.util.Strings;

import java.lang.reflect.Field;

/**
 * @author fgh
 */
public enum JsonFieldNamingPolicy implements FieldNamingStrategy {
    GsonProperty() {
        @Override
        public String translateName(Field f) {
            com.zfei.gfb.util.gson.GsonProperty annotation = f.getAnnotation(com.zfei.gfb.util.gson.GsonProperty.class);
            if (annotation != null && Strings.isNotEmpty(annotation.value())) {
                return annotation.value();
            }
            return f.getName();
        }
    }
}
